<?php
class helper_interface_money
{
/**
	 * 
	 * @return 查询的用户对象
	 * @var Userbase
	 */
	protected $userbase = null;
	
	/**
	 * 
	 * Enter description here ...
	 * @var string|用户手机号码
	 */
	protected $mobile = null;
	/**
	 * 
	 * @return 点卡充值接口地址
	 * @var string
	 */
	const APP_URL = 'http://218.246.196.118/astgo/wap/call.php?a={$mobile}';
	/**
	 * 
	 * @return 出错时可提取错误信息
	 * @var string
	 */
	public  $errmsg = '';
	
	/**
	 * 
	 *2011-12-30-下午04:44:09 by 460932465
	 * Enter description here ...
	 * @param string|手机号码 $mobile
	 */
	function __construct($mobile )
	{
		if (is_string($mobile))
		{
			$this->mobile = $mobile;
		}else if (is_array($mobile))
		{
			$this->userbase = Userbase::find('userphone = ?',$mobile)->getOne();
		}
	}
	function set_usermobile($mobile)
	{
		$this->mobile = $mobile;
	}
	/**
	 * 
	 *2012-1-2-上午11:54:57 by 460932465
	 * @return 查询用户余额
	 */
	function get_money()
	{
		if(is_null($this->mobile) && is_null($this->userbase))
		{
			$this->errmsg = '没有设置用户对象';
			return false;
		}else
		{
			//提取查询URL
					$url = str_replace('{$mobile}',$this->_getUserPhone(),self::APP_URL);
			//开始提交
					$result = Helper_Common::curl($url);
					$result = Helper_Common::get_split('<center>','</center>',$result);
					return $this->_check_status($result);
		}
	}	

	protected function _getUserPhone()
	{
		if (is_null($this->userbase))
		{
			return $this->mobile;
		}else
		{
			return $this->userbase->userphone;
		}	
	}
	protected function _check_status($result)
	{
		if (strpos($result,'ERR') === false)
		{
			return $result;	
		}else
		{
			return false;
		}
	}
}

?>